From 00442eb62b331e6c08cc612aa0e0cdd4447afaa6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 27 Aug 2018 01:38:15 +0200 Subject: [PATCH] tools: improve html output of babl_fish_path_fitness Illustrate memory throughput as read+writte/time, providing a metric that works for comparing conversions against each other on a single machine. --- tools/babl_fish_path_fitness.c | 177 +++++++++++++++++++++++++++++---- 1 file changed, 158 insertions(+), 19 deletions(-) diff --git a/tools/babl_fish_path_fitness.c b/tools/babl_fish_path_fitness.c index cd012c0..bcc8741 100644 --- a/tools/babl_fish_path_fitness.c +++ b/tools/babl_fish_path_fitness.c @@ -18,11 +18,11 @@ int ok = 0; static int qux = 0; -#define UTF8 +//#define UTF8 #ifdef UTF8 -static char *utf8_bar[] = { " ", "·", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" }; +static char *utf8_bar[] = { " %s", "·%s", "▁%s", "▂%s", "▃%s", "▄%s", "▅%s", "▆%s", "▇%s", "█%s" }; #define DIRECT " " #define SELF " " #define EMPTY " " @@ -33,17 +33,17 @@ static char *utf8_bar[] = { " ", "·", "▁", "▂", "▃", "▄", "▅", "▆", static char *utf8_bar[] = { " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " "}; + "▄", + "▄", + "▄", + "▄", + "▄", + "▄", + "▄", + "▄"}; #define SL "
" -#define SELF " " -#define EMPTY " " +#define SELF " " +#define EMPTY "▄" #define NL "
\n" #endif @@ -56,21 +56,152 @@ static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"}; */ +#define NUM_TEST_PIXELS (1024*256) +static float test_pixels_float[NUM_TEST_PIXELS*4]; +static char test_pixels_in[NUM_TEST_PIXELS * 6 * 8]; +static char test_pixels_out[NUM_TEST_PIXELS * 6 * 8]; + + +static double rand_double (void) +{ + return (double) random () / RAND_MAX; +} + +static double rand_range_double (double min, double max) +{ + return rand_double () * (max - min) + min; +} + +static void init_test_pixels (void) +{ + static int done = 0; + int i = 0; + int pix_no = 0; + srandom (111); + + if (done) + return; + done = 1; + + + for (i = 0; i < 256 && pix_no < NUM_TEST_PIXELS; i++) + { + test_pixels_float[pix_no*4+0] = rand_double(); + test_pixels_float[pix_no*4+1] = rand_double(); + test_pixels_float[pix_no*4+2] = rand_double(); + test_pixels_float[pix_no*4+3] = rand_double(); + pix_no ++; + } + for (i = 0; i < 256 && pix_no < NUM_TEST_PIXELS; i++) + { + test_pixels_float[pix_no*4+0] = rand_range_double(1.0, 2.0); + test_pixels_float[pix_no*4+1] = rand_range_double(1.0, 2.0); + test_pixels_float[pix_no*4+2] = rand_range_double(1.0, 2.0); + test_pixels_float[pix_no*4+3] = rand_range_double(1.0, 2.0); + pix_no ++; + } + for (i = 0; i < 256 && pix_no < NUM_TEST_PIXELS; i++) + { + test_pixels_float[pix_no*4+0] = rand_range_double(-1.0, 1.0); + test_pixels_float[pix_no*4+1] = rand_range_double(-1.0, 1.0); + test_pixels_float[pix_no*4+2] = rand_range_double(-1.0, 1.0); + test_pixels_float[pix_no*4+3] = rand_range_double(-1.0, 1.0); + pix_no ++; + } + for (i = 0; i < 16 && pix_no < NUM_TEST_PIXELS; i++) + { + test_pixels_float[pix_no*4+0] = rand_range_double(0.0, 1.0); + test_pixels_float[pix_no*4+1] = rand_range_double(0.0, 1.0); + test_pixels_float[pix_no*4+2] = rand_range_double(0.0, 1.0); + test_pixels_float[pix_no*4+3] = 0; + pix_no ++; + } + for (i = 0; i < 16 && pix_no < NUM_TEST_PIXELS; i++) + { + test_pixels_float[pix_no*4+0] = rand_range_double(0.0, 16.0); + test_pixels_float[pix_no*4+1] = rand_range_double(0.0, 16.0); + test_pixels_float[pix_no*4+2] = rand_range_double(0.0, 16.0); + test_pixels_float[pix_no*4+2] = rand_range_double(-1.0, 1.0); + pix_no ++; + } + for (i = 0; pix_no < NUM_TEST_PIXELS; i++) + { + test_pixels_float[pix_no*4+0] = rand_range_double(-1.0, 61.0); + test_pixels_float[pix_no*4+1] = rand_range_double(-1.0, 61.0); + test_pixels_float[pix_no*4+2] = rand_range_double(-1.0, 66.0); + test_pixels_float[pix_no*4+3] = rand_range_double(-1.0, 3.0); + pix_no ++; + } + for (i = 0; i < sizeof(test_pixels_in); i++) + test_pixels_in[i]=(rand()/10000)&0xff; +} + static int destination_each (Babl *babl, void *userdata) { Babl *source = userdata; Babl *destination = babl; + init_test_pixels (); if (qux % babl_formats_count () == qux / babl_formats_count ()) printf (SELF); else { Babl *temp = babl_fish_path (source, destination); + const Babl *fish = babl_fish (source, destination); + + char style[128] = ""; + char title[1024] = ""; +#ifdef UTF8 +#else + { + long bytes_in = 0; + long bytes_out = 0; + float bytes_per_second; + long ticks_start, ticks_end; + + ticks_start = babl_ticks (); + babl_process (fish, &test_pixels_in[0], + &test_pixels_out[0], + NUM_TEST_PIXELS); + ticks_end = babl_ticks (); + bytes_in = NUM_TEST_PIXELS * babl_format_get_bytes_per_pixel (source); + bytes_out = NUM_TEST_PIXELS * babl_format_get_bytes_per_pixel (destination); + + bytes_per_second = (bytes_in + bytes_out) / ((ticks_end - ticks_start)/1000.0); + + { + float colval = bytes_per_second/1024/1024.0/7.0; + if (colval > 1) colval = 1; + + if (colval < 0.2) + { + sprintf (style, "color:rgb(%i, 0, 0);", (int)(colval * 5 * 255)); + } + else if (colval < 0.4) + { + sprintf (style, "color:rgb(255, %i, 0);", (int)((colval-0.2) * 5 * 255)); + } + else + { + sprintf (style, "color:rgb(255, 255, %i);", (int)((colval-0.4) * 1.666 * 255)); + } + + + + } + { + int steps = 0; + if (temp) + steps = babl_list_size (temp->fish_path.conversion_list); + sprintf (title, "%s to %s %i steps %.3fgb/s ", babl_get_name (source), babl_get_name (destination), steps, bytes_per_second/1024.0/1024.0); + } + } +#endif if (temp) { - printf ("%s", utf8_bar[babl_list_size (temp->fish_path.conversion_list)]); + printf (utf8_bar[babl_list_size (temp->fish_path.conversion_list)], title, style); total_length += babl_list_size (temp->fish_path.conversion_list); total_cost += temp->fish_path.cost; ok++; @@ -78,7 +209,7 @@ static int destination_each (Babl *babl, } else { - printf (EMPTY); + printf (EMPTY, title, style); total++; } } @@ -114,10 +245,11 @@ int main (void) printf ("\n"); - printf ("\n"); + printf ("

babl profiling matrix, rows are source formats columns are destinations, blue background means direct conversion and blue left border means multi-step conversion, no blue means reference conversion, gradient from black, through red, yellow and white indicates memory-bandwidth sum bytes read + bytes written / time, hover items to see further details on an individual conversion.

\n"); #endif -- 2.30.2